#ifndef _SYMBOL_H
#define _SYMBOL_H

#include "list.h"
#include "scanner.h"

enum sym_type
{
  GLOBAL_VAR,
  FUNCTION,
  AUTO_VAR,
};

enum var_type
{
  TYPE_INT,
  TYPE_VOID,
};

struct func_info
{
  struct list_head param_head;
  struct list_head auto_head;
  int return_type;
  int param_size;
};

struct param_info
{
  char name[MAX_NAME_SZ];
  struct list_head param_list;
  int type;
  int size;
  int seq;
  int offset;
  int is_array;
};

struct arg_info
{
  char name[MAX_NAME_SZ];
  char addr[16];
  struct list_head arg_list;
  int type;
  int size;
};

struct auto_info
{
  char name[MAX_NAME_SZ];
  struct list_head auto_list;
  int type;
  int size;
  int seq;
  int offset;
  int is_array;
  int level;/*depth*/
  int block_no;/*belong which block*/
};


struct global_info
{
  int size;
  int type;
  int is_array;
};

struct cminus_symbol
{
  char name[MAX_NAME_SZ];
  int sym_type;/*0-global-var 1-func*/
  struct list_head sym_list;
  union
  {
    struct func_info f;/*for function*/
    struct global_info g;/*for variable*/
  }u;
};

void sym_table_init();
int insert_global_var_symbol(struct cminus_symbol *sym);
struct cminus_symbol *insert_function_symbol(char *name);
struct cminus_symbol *lookup_global_var(char *name);
struct cminus_symbol *lookup_function(char *name);
struct auto_info *lookup_auto_var(char *name);
struct param_info *lookup_param(char *name);
#endif

